const http = require('http')//核心模块
const path = require('path')//核心模块
const fs = require('fs')//核心模块
const server = http.createServer()

server.on('request', (req, res) => {
  console.log(req.url);
  if (req.url == '/index.html') {
    // res.end('index.html')
    fs.readFile(path.join(__dirname, 'dist/index.html'), (err, data) => {
      // console.log(data.toString());
      res.end(data.toString())
    })

  } else if (req.url == '/index.css') {
    // res.end('index.html')
    fs.readFile(path.join(__dirname, 'dist/index.css'), (err, data) => {
      // console.log(data.toString());
      res.end(data.toString())
    })

  } else {
    res.end('111')
  }
  // /* 设置响应头 */
  // res.setHeader('Content-Type', 'text/html;charset=utf-8')
  // res.end('[1,2,3,4,5]')//只能返回字符串
})

server.listen('3333', () => {
  console.log('http://127.0.0.1:3333');
})